package psd.model.Prolog.Converters;

import java.util.List;

import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologJavadocConverter extends PrologConverter
implements IConverter<Javadoc>{

	protected PrologJavadocConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(Javadoc node) {
		   int startPosition = node.getStartPosition();
	        int length = node.getLength();
	        String id = idResolver.getID(node);
	        if(node.getParent().getNodeType() == 23)
	        {
	            FieldDeclaration parentNode = (FieldDeclaration)node.getParent();
	            List list = parentNode.fragments();
	            int size = list.size();
	            for(int i = 0; i < size; i++)
	            {
	                String fragmentid = idResolver.getID((VariableDeclarationFragment)list.get(i));
	                String temp_id = idResolver.getID();
	                String args[] = {
	                    temp_id, fragmentid, "javaDoc", this.getFilePath(node), this.getLineNumber(node)
	                };
	                writer.writeFact("commentT", args);
	                writer.writeFact("slT", new String[] {
	                    temp_id, Integer.toString(startPosition), Integer.toString(length), this.getFilePath(node), this.getLineNumber(node)
	                });
	            }

	        } else
	        {
	            String owner = getParentId(node);
	            String args[] = {
	                id, owner, "javaDoc", this.getFilePath(node), this.getLineNumber(node)
	            };
	            writer.writeFact("commentT", args);
	            writer.writeFact("slT", new String[] {
	                id, Integer.toString(startPosition), Integer.toString(length), this.getFilePath(node), this.getLineNumber(node)
	            });
	        }
	        return false;
	}

}
